package com.heima.crm.controller;

import com.heima.crm.common.result.PageResult;
import com.heima.crm.common.result.Result;
import com.heima.crm.pojos.dtos.ChannelStatisticsQueryDto;
import com.heima.crm.pojos.dtos.ClueStatisticsQueryDto;
import com.heima.crm.pojos.dtos.CustomerStatisticsQueryDto;
import com.heima.crm.pojos.dtos.SellStatisticsQueryDto;
import com.heima.crm.service.StatisticsService;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@RequestMapping("/statistics")
@RequiredArgsConstructor
public class StatisticsController {
    private final StatisticsService statisticsService;

    /**
     * 客户统计图表
     *
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/customer/chart")
    public Result cusChart(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        return statisticsService.cusChart(begin, end);
    }

    /**
     * 客户统计报表
     *
     * @param dto
     * @return
     */
    @GetMapping("/customer/page")
    public Result cusPage(CustomerStatisticsQueryDto dto) {
        return statisticsService.cusPage(dto);
    }

    /**
     * 销售统计图表
     *
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/sell/chart")
    public Result sellChart(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        return statisticsService.sellChart(begin, end);
    }

    /**
     * 销售统计报表
     *
     * @param dto
     * @return
     */
    @GetMapping("/sell/page")
    public Result sellPage(SellStatisticsQueryDto dto) {
        return statisticsService.sellPage(dto);
    }

    /**
     * 线索统计图表
     *
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/clue/chart")
    public Result clueChart(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        return statisticsService.clueChart(begin, end);
    }

    /**
     * 线索统计报表
     * @param dto
     * @return
     */
    @GetMapping("/clue/page")
    public Result cluePage(ClueStatisticsQueryDto dto) {
        return statisticsService.cluePage(dto);
    }

    /**
     * 渠道统计图表
     *
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/channel/chart")
    public Result channelChart(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                               @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        return statisticsService.channelChart(begin,end);
    }

    /**
     * 渠道统计报表
     * @param dto
     * @return
     */
    @GetMapping("/channel/page")
    public Result channelPage(ChannelStatisticsQueryDto dto) {
        return statisticsService.channelPage(dto);
    }
}
